The View is implemented using Java Server Pages (JSP). Java Server Pages are normally filled with embedded Java code, but the Struts framework provides extension tags for numerous functions including generating and populating html controls (<html:text>), managing errors (<html:errors>), and iterating over data lists (<logic:iterate>). The following JSP files are used in Dwarf Manager:
Note the following are static screen shots. This site is not dynamically hosted.
| Generated HTML | JSP Source (View->Source) |
| Main | Main.jsp |
| AddDwarf | AddDwarf.jsp |
| AddMountain | AddMountain.jsp |
| UpdateDwarf | UpdateDwarf.jsp |
| UpdateMountain | UpdateMountain.jsp |
The Model is implemented as Java Beans subclassed from ActionForm. Three Form beans were defined:
| Form Beans |
| MainForm.java |
| DwarfForm.java |
| MountainForm.java |
The Controller portion of the struts framework automatically copies data between the Model Form Beans and the View JSP pages. The controller logic for each page is implemented in subclasses of the Action class:
| Action Classes |
| EnterMainAction.java |
| AddDwarfAction.java |
| EditDwarfAction.java |
| SaveDwarfAction.java |
| AddMountainAction.java |
| EditMountainAction.java |
| SaveMountainAction.java |
The page flow and the relationships between the models, views, and controllers are configured in the struts-config.xml file.
Underneath the model the data is stored in the Postgresql SQL database. The following database files were used:
| SQL Files |
| Dwarf_Schema.sql |
| Dwarf_Load.sql |
| Drop_Database.sql |
Java Bean data objects were defined to encapsulate data returned from the database:
| Data Objects |
| Dwarf.java |
| Mountain.java |
Rows from the Database object are initially returned as a DbRowSet, but are copied to lists of data objects because the Struts APIs and tag libraries operate on Java Beans, not list-of-hash-style RowSets [note the difference with ASP.NET, whose controls accept ADO.NET database DataSets directly]. Database queries are performed inside Mgr objects:
| Mgr Objects |
| DwarfMgr.java |
| MountainMgr.java |
Struts also supports separate message catalogs for localization. Dwarf Manager does not use this facility, except the Form validation will return error messages from the ApplicationResources.properties file.
While Java Dwarf Manager does require more code than the C# equivalent, some of this code can be produced using a Code Generator.
The simple back-end jdbc database classes can also be replaced with EJBs.
The source for the Java Dwarf Manager web site is available in this tar file. All code was developed using Java 1.3.1 on Mac OS X.